package com.betterjr.modules.risk.loan.data;

import java.math.BigDecimal;

import com.betterjr.common.utils.MathExtend;
import com.betterjr.modules.risk.loan.dao.CalculateChargeLinkChain;
import com.betterjr.modules.risk.loan.entity.LoanProjectCharge;

public class MultiplyFirstCalculate implements CalculateChargeLinkChain {

    @Override
    public BigDecimal invokeChain(LoanProjectCharge charge) {

        // 贷款金额*费率*融资期限/360

        if (charge.getLoanBalance() != null && charge.getServiceRate() != null
                && charge.getFinancingMaturityDate() != null && charge.getFinancingMaturityDate() != 0l) {

            BigDecimal multiply = charge.getLoanBalance().multiply(charge.getServiceRate())
                    .multiply(new BigDecimal(charge.getFinancingMaturityDate()));
            BigDecimal divide = MathExtend.divide(multiply, new BigDecimal(360));

            return divide;

        }

        return new BigDecimal(0);
    }

}
